<?php
/**
 * zsuper_mayi functions and definitions.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package zsuper_mayi
 */

/*----------------------------------------------------------------------*/
/* 全局参数定义 */
/*----------------------------------------------------------------------*/
define('THEME_DIR', trailingslashit( get_template_directory() ));
define('THEME_URL', trailingslashit( get_template_directory_uri() ));
define('INC_DIR', THEME_DIR . 'inc/');
define('INC_URL', THEME_URL . 'inc/');
define('CSS_DIR', THEME_DIR . 'layouts/');
define('CSS_URL', THEME_URL . 'layouts/');
define('ZS_DIR', THEME_DIR . 'zsuper-framework/');
define('ZS_URL', THEME_URL . 'zsuper-framework/');
define('IMG_URL', THEME_URL . 'images/');
define('IMG_DIR', THEME_DIR . 'images/');
define('OPTION_URL', ZS_URL . 'acf/');
define('OPTION_DIR', ZS_DIR . 'acf/');

/*----------------------------------------------------------------------*/
/* 引入依赖文件 */
/*----------------------------------------------------------------------*/
include_once (ZS_DIR . 'remove-head.php');
//include_once (ZS_DIR . 'custom-excerpt.php');
include_once (ZS_DIR . 'post-functions.php');
include_once (ZS_DIR . 'paginate-links.php');
include_once (ZS_DIR . '/widgets/widgets-info.php');
include_once (ZS_DIR . 'option.php');//选项页面


if ( ! function_exists( 'zsuper_mayi_setup' ) ) :
/**
 * 初始化主题默认选项及功能
 *
 * 注意: 本函数挂载在'after_setup_theme'钩子上, 此钩子比'init'钩子先运行. 因为'init'
 * 钩子对于某些功能需求运行的太晚以至于无法实现功能, 比如添加主题支持文章特色图像功能.
 */
function zsuper_mayi_setup() {
	/*
	 * 使主题支持多语种翻译
	 * 将翻译文件放在 /languages/ 文件夹.
	 */
	load_theme_textdomain( 'zsuper_mayi', get_template_directory() . '/languages' );

	// 使默认文章及评论支持RSS订阅链接.
	add_theme_support( 'automatic-feed-links' );

	/*
	 * 通知wordpress主题自身没有定义<title>标签
	 * 通过声明title-tag来通知wordpress可以添加标题而无需担心会导致重复添加
	 */
	add_theme_support( 'title-tag' );

	/*
	 * 开启文章及页面特色图像功能
	 *
	 * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
	 */
	add_theme_support( 'post-thumbnails' );

	// 导航栏注册
	register_nav_menus( array(
		'primary' => esc_html__( '主菜单', 'zsuper_mayi' ),
	) );
	// 移动设备导航菜单注册
	/*register_nav_menus( array(
		'mobile' => esc_html__( '移动设备导航', 'zsuper_mayi' ),
	) );*/

	/*
	 *开启HTML5支持
	 */
	add_theme_support( 'html5', array(
		'search-form',
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );

	/*
	 * 定义文章形式
	 */
	add_theme_support( 'post-formats', array(
		'aside',
		'image',
		'video',
		'quote',
		'link',
	) );

	// 定义网站背景
	add_theme_support( 'custom-background', apply_filters( 'zsuper_mayi_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );
}
endif;
add_action( 'after_setup_theme', 'zsuper_mayi_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function zsuper_mayi_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'zsuper_mayi_content_width', 640 );
}
add_action( 'after_setup_theme', 'zsuper_mayi_content_width', 0 );

/**
 * 注册sidebar区域
 *
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function zsuper_mayi_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar', 'zsuper_mayi' ),
		'id'            => 'sidebar-1',
		'description'   => esc_html__( 'Add widgets here.', 'zsuper_mayi' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( '首页', 'zsuper_mayi' ),
		'id'            => 'sidebar-2',
		'description'   => esc_html__( 'Add widgets here.', 'zsuper_mayi' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
}
add_action( 'widgets_init', 'zsuper_mayi_widgets_init' );
/**
 * 注册和引入样式
 */
function zsuper_mayi_style()
{
    wp_register_style('zsuper_fontawesome',CSS_URL . 'font-awesome-4.7.0/css/font-awesome.min.css', array() , '20170115' );
    wp_register_style('zsuper_animate', CSS_URL .'animate.css',array(),'20170115' );
    wp_register_style('zsuper_swiper',CSS_URL . 'swiper.min.css',array(),'20170115' );
    wp_register_style('zsuper_web',CSS_URL . 'style.css', array() , '20170115' );
    wp_register_style('zsuper_customize' , get_stylesheet_uri() , array('zsuper_fontawesome','zsuper_animate','zsuper_swiper','zsuper_web'),'20170115');
    wp_enqueue_style( 'zsuper_fontawesome');
    wp_enqueue_style('zsuper_animate' );
    wp_enqueue_style('zsuper_swiper' );
    wp_enqueue_style('zsuper_web' );
    wp_enqueue_style('zsuper_customize' );

}
add_action('wp_enqueue_scripts' , 'zsuper_mayi_style' );
/**
 * 注册和引入脚本
 */
function zsuper_mayi_scripts() {
    //自定义加载的脚本
    wp_register_script('zsuper_jquery' ,THEME_URL . 'js/min/jquery-1.8.3.min.js' , array(), '1.8.3' , true );
    wp_register_script('zsuper_SuperSlidejs' , THEME_URL . 'js/min/jquery.SuperSlide.2.1.1.js',array('zsuper_jquery'),'2.1.1',true );
    wp_register_script('zsuper_mboxjs' , THEME_URL . 'js/min/mbox-min.js',array('zsuper_jquery'),'20170115',true );
    // wp_register_script('zsuper_pubjs' , THEME_URL . 'js/min/pub-min.js',array('zsuper_jquery'),'20170115',true );
    wp_register_script('zsuper_pubjs' , THEME_URL . 'js/pub.js',array('zsuper_jquery'),'20170115',true );
    wp_enqueue_script('zsuper_jquery' );
    wp_enqueue_script('zsuper_SuperSlidejs' );
    wp_enqueue_script('zsuper_mboxjs' );
    wp_enqueue_script('zsuper_pubjs' );

    //实现移动设备上的菜单开关下拉功能
    // wp_enqueue_script( 'zsuper_mayi-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
    //兼容性修补不定
	wp_enqueue_script( 'zsuper_mayi-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'zsuper_mayi_scripts' );

/**
 * Implement the Custom Header feature.
 */
require INC_DIR . 'custom-header.php';
/**
 * Custom template tags for this theme.
 */
require INC_DIR . 'template-tags.php';

/**
 * Custom functions that act independently of the theme templates.
 */
require INC_DIR . 'extras.php';

/**
 * Customizer additions.
 */
require INC_DIR . 'customizer.php';

/**
 * Load Jetpack compatibility file.
 */
require INC_DIR . 'jetpack.php';
